#include <iostream>
#include <string>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/date_time.hpp>
#include <boost/thread.hpp>

#include "../ClientSession.hpp"

int main(int argc, char* argv[])
{
	if (argc < 3)
	{
		std::cerr << "Usage: dbmaster <host> <port>\n";
		return 1;
	}

	try
	{
		boost::asio::io_service io_service;

		boost::asio::ip::tcp::resolver resolver(io_service);
		boost::asio::ip::tcp::resolver::query query(argv[1], argv[2]);
		boost::asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query);

		ClientSession sc(io_service, iterator, "", false, false);

		boost::thread t(boost::bind(&boost::asio::io_service::run, &io_service));

		std::string line;
		while (getline(std::cin, line))
		{
			boost::shared_ptr<std::string> str_p(new std::string(line));
			sc.write(str_p, 0);
		}

	}
	catch (std::exception& e)
	{
		std::cerr << "Exception: " << e.what() << "\n";
	}
}